import request from '@/utils/request'

/**
 * 获取所有代理商
 * @param params 值
 * @returns {AxiosPromise}
 */
export function getAgentListApi(params) {
  return request({
    url: '/api/Agents',
    method: 'GET',
    headers: {
      Accept: 'application/json'
    },
    params: Object.assign(params, { isGet: true })
  });
};

/**
 * 获取指定代理
 * @param id
 * @returns {AxiosPromise}
 */
export function getAppointAgentInfoApi(id) {
  return request({
    url: `/api/Agents/${ id }`,
    method: 'GET',
    headers: {
      Accept: 'application/json'
    },
    params: Object.assign({}, { isGet: true })
  });
};

/**
 * 获取所有代理商角色
 * @returns {AxiosPromise}
 */
export function getAgentRolesListApi() {
  return request({
    url: `/api/AgentRoles`,
    method: 'GET',
    headers: {
      Accept: 'application/json'
    }
  })
}

/**
 * 获取所有代理商客户列表
 * @param id 客户ID
 * @param params 值
 * @returns {AxiosPromise}
 */
export function getAgentClientListApi(id, params) {
  return request({
    url: `/api/Agents/${id}/Clients`,
    method: 'GET',
    headers: {
      Accept: 'application/json'
    },
    params: Object.assign(params, { isGet: true })
  });
};

/**
 * 修改推广人
 * @param userId
 * @param data
 * @returns {AxiosPromise}
 * @constructor
 */
export function PUTUserEditListApi(userId, data) {
  return request({
    url: `/api/Users/${userId}/AgentReferences`,
    method: 'PUT',
    headers: {
      isToken: true
    },
    data: data
  })
}

/**
 * 清除上级推广人
 * @param id
 * @returns {AxiosPromise}
 * @constructor
 */
export function DELETEUserDelAPi(id) {
  return request({
    url: `/api/Users/${id}/AgentReferences`,
    method: 'DELETE',
    headers: {
      isToken: true
    }
  })
}

/**
 * 添加代理商
 * @returns {AxiosPromise}
 * @constructor
 */
export function POSTAddAgentApi(data) {
  return request({
    url: `/api/Agents`,
    method: 'POST',
    data
  })
}

/**
 * 编辑代理商
 * @param data 修改的值
 * @returns {AxiosPromise}
 * @constructor
 */
export function PUTEditAgentApi(id, data) {
  return request({
    url: `/api/Agents/${id}`,
    method: 'PUT',
    data
  })
}

/**
 * 批量删除代理商
 * @param batchId ID
 * @returns {AxiosPromise}
 * @constructor
 */
export function DELETBatchAgentApi(batchId) {
  return request({
    url: `/api/Agents/${batchId}`,
    method: 'DELETE',
  })
}

/**
 * 查询代理商角色
 * @param params 查询信息
 * @returns {AxiosPromise}
 */
export function getRolesListApi(params) {
  return request({
    url: '/api/AgentRoles',
    method: 'GET',
    headers: {
      Accept: 'application/json'
    },
    params: Object.assign(params, { isGet: true })
  });
};

/**
 * 批量删除代理商角色
 * @param batchId
 * @returns {AxiosPromise}
 * @constructor
 */
export function DELETBatchAgentRolesApi(batchId) {
  return request({
    url: `/api/AgentRoles/${batchId}`,
    method: 'DELETE',
    headers: {
      isToken: true
    }
  })
}

/**
 * 查询代理商级别
 * @param params
 * @returns {AxiosPromise}
 */
export function getAgentRoleLevelsApi(params) {
  return request({
    url: '/api/AgentLevels',
    method: 'GET',
    headers: {
      isToken: true,
      Accept: 'application/json'
    },
    params
  })
}

/**
 * 添加代理商角色
 * @param data 数据
 * @returns {AxiosPromise}
 * @constructor
 */
export function POSTAddAgentRolesApi(data) {
  return request({
    url: `/api/AgentRoles`,
    method: 'POST',
    data
  })
}

/**
 * 代理商推广订单
 * @param id
 * @param params
 * @returns {AxiosPromise}
 */
export function getExtensionListApi(id, params) {
  return request({
    url: `/api/agents/${id}/clientOrders`,
    method: 'GET',
    headers: {
      Accept: 'application/json'
    },
    params: Object.assign(params, { isGet: true })
  });
};

/**
 * 获取所有上级代理商
 * @param id
 * @param params
 * @returns {AxiosPromise}
 */
export function getRefAgentApi(level, params) {
  return request({
    url: `/api/refAgents/${ level }`,
    method: 'GET',
    headers: {
      Accept: 'application/json'
    },
    params: Object.assign(params, { isGet: true })
  });
};

/**
 * 获取代理设置
 */
export function spreadConfigApi() {
  return request({
    url: `/api/system/agentConfig`,
    method: 'GET',
    params: Object.assign({}, { isGet: true })
  });
};

/**
 * 修改代理设置
 * @param data 数据
 * @returns {AxiosPromise}
 */
export function spreadConfigUpdateApi(data) {
  return request({
    url: `api/system/agentConfig`,
    method: 'PUT',
    data
  });
};
